package com.speedchina.oauth2_permission.web.sys.api_v1;

import com.speedchina.common.download.utils.CsvWriter;
import com.speedchina.common.download.utils.ExcelUtils;
import com.speedchina.framework.base.BaseController;
import com.speedchina.framework.base.QueryModel;
import com.speedchina.framework.model.R;
import com.speedchina.permission.base.i18n.I18nService;
import com.speedchina.permission.domain.sys.dto.SysLogLoginDTO;
import com.speedchina.permission.domain.sys.entity.SysLogLogin;
import com.speedchina.permission.domain.sys.po.SysLogLoginPo;
import com.speedchina.permission.service.sys.SysLogLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 *  接口
 * @author Winter
 * @date 2021-06-09 16:10:43
 */
@RestController
@RequestMapping("/sys/sysLogLogin")
@Api(description = " 接口")
public class SysLogLoginController extends BaseController<SysLogLoginService, SysLogLogin, SysLogLoginDTO> {

    @Autowired
    private I18nService i18nService;

    @Autowired
    private SysLogLoginService service;

    @ApiOperation("分页查询")
    @GetMapping
    // @SysLog("分页查询-")
    // @PreAuthorize("hasAuthority('sys:sysLogLogin:list')")
    public R query(Integer pageNo, Integer pageSize, SysLogLoginPo params) {
        return R.page(service.queryPage(new QueryModel<>(pageNo, pageSize, params)));
    }

    @ApiOperation("详情查询")
    @GetMapping("/get")
    // @SysLog("详情查询-")
    // @PreAuthorize("hasAuthority('sys:sysLogLogin:info')")
    public R get(SysLogLoginPo params) {
        return R.data(service.get(params));
    }



    @ApiOperation("批量删除")
    @DeleteMapping("/{ids}")
    // @SysLog("批量删除-")
    // @PreAuthorize("hasAuthority('sys:sysLogLogin:delete')")
    public R delete(@PathVariable("ids") String strIds) {
        return R.data(this.deleteBatch(strIds));
    }

    @ApiOperation("下载数据到excel")
    @GetMapping("downloadExcel")
    //@SysLog("下载--数据")
    //@PreAuthorize("hasAuthority('sys:user:downloadExcel')")
    public void downloadExcel(HttpServletResponse response, SysLogLoginPo params) {
        ExcelUtils.downLoadExcel(response,service.queryList(params),SysLogLoginDTO.class,"文件名");
    }

    @ApiOperation("下载数据到csv")
    @GetMapping("/downloadCsv")
    //@SysLog("下载--数据")
    //@PreAuthorize("hasAuthority('sys:user:downloadCsv')")
    public void downloadCsv(HttpServletResponse response, SysLogLoginPo params) {
        CsvWriter.downloadCsv( response,service.queryList(params), SysLogLoginDTO.class,"文件名");
    }

}
